﻿using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

public class FireControlsystem : MonoBehaviour
{
    public bool isRun;      //是否运行
    public GameObject bullet;
    public Transform firePosObj;    //发射点位置
    float timer;
    float fireRate;          //子弹发射频率
    public float firePower;
    public GameObject fireFlash;
    private int index_bullet = 0;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (isRun)
            return;
        timer += Time.deltaTime;
        if(timer>fireRate)
        {
            timer = 0;

            //实例化子弹和枪火焰
            //var shell = Instantiate(bullet, firePosObj.position, firePosObj.rotation);
            //GameObject flash = Instantiate(fireFlash, firePosObj.transform);

            //获取炮弹刚体，添加力
            //shell.GetComponent<Rigidbody>().AddForce(Vector3.forward * firePower);
            ObjectPool.objArray[index_bullet].GetComponent<Rigidbody>().isKinematic = false;
            ObjectPool.objArray[index_bullet].GetComponent<Rigidbody>();

        }
    }

    private void Awake()
    {
        if (firePosObj == null)
            Debug.LogError("请将发射点物体拖入参数栏");
        if(bullet==null)
        {
            Debug.LogError("请将发射子弹体拖入参数栏");
        }
    }


}
